//
//  HZPeiziMyStockVC.m
//  Stock_Stategy
//
//  Created by MayerF on 2017/11/29.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZPeiziMyStockVC.h"
#import "HZPeiziQueryView.h"
#import "MYHttp.h"

@interface HZPeiziMyStockVC ()
@property (nonatomic, strong)HZPeiziQueryView *pQueryView;
@end

@implementation HZPeiziMyStockVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的持仓";
    
    //关联逻辑管理对象
    self.logicManager = [HZBaseLogjcManager new];
    self.view.logicManager = self.logicManager;
    
    _pQueryView = [HZPeiziQueryView new];
    _pQueryView.nQueryType = kQuery_own_Type;
    [self.view addSubview:_pQueryView];
    [_pQueryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    [self p_registerBlock];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self sendRequest];
}

#pragma mark -
#pragma mark blockAction
- (void)p_registerBlock
{
    __weak typeof (self)weakSelf = self;
    [self.logicManager mapLogic:kLogicRouterPeiziBuy toBlock:^id(NSDictionary *params, id other) {
        UIViewController *nextVC = [[MYRouter shared] matchController:kRouterPeiziBuySell params:@{@"type": @(1),@"code":other}];
        [weakSelf.navigationController pushViewController:nextVC animated:YES];
        return nil;
    }];
    [self.logicManager mapLogic:kLogicRouterPeiziSell toBlock:^id(NSDictionary *params, id other) {
        UIViewController *nextVC = [[MYRouter shared] matchController:kRouterPeiziBuySell params:@{@"type": @(2),@"code":other}];
        [weakSelf.navigationController pushViewController:nextVC animated:YES];
        return nil;
    }];
}

- (void)sendRequest
{
    NSString *date = @"1";
    NSString *status = @"1";
    NSString *total = @"0";
    [self p_sendExcutingRequestWithDate:date sellStatus:status total:total];
}
#pragma mark -
#pragma mark request
- (void)p_sendExcutingRequestWithDate:(NSString *)date
                           sellStatus:(NSString *)sellStatus
                                total:(NSString *)total
{
    [SVProgressHUD show];
    
    NSArray *array = @[@{@"funcid":@"4",@"session":[HZUserManager manager].peiziAccountSession}];
    [MYHttp post:kAPIPeiziHost params:array success:^(id response) {
        NSMutableArray *tempArray = [NSMutableArray array];
        if([response isKindOfClass:[NSArray class]]){
            for (NSDictionary *dict in response) {
                HZPeiziTradeStockListModel *model = [HZPeiziTradeStockListModel mj_objectWithKeyValues:dict];
                [tempArray addObject:model];
            }
        }
        [_pQueryView updateNewData:tempArray];
        [SVProgressHUD dismiss];
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:error.domain];
    }];
}

@end
